package com.bite.system.test;

import com.bite.common.core.domain.R;
import com.bite.common.core.enums.ResultCode;
import com.bite.system.domain.SysUser;
import com.bite.system.test.domain.dto.ValidationDTO;
import com.bite.system.test.service.ITestService;

import com.bite.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
public class testController {

    @Autowired
    private ITestService testService;

    @Autowired
    private RedisService redisService;


    @GetMapping("/list")
    public List<?> list(){
        return  testService.getList();
    }


    @GetMapping("/add")
    public String add(){
        return testService.add();
    }

    @GetMapping("/apifox")
    public R<String> apifox(String apiId){
        R<String> r = new R();
        r.setCode(ResultCode.SUCCESS.getCode());
        r.setMsg(ResultCode.SUCCESS.getMsg());
        r.setData("apifox"+apiId);
        return r;
    }


    @GetMapping("/redis")
    public String redisAddAndGet() {
        SysUser sysUser = new SysUser();
        sysUser.setUserAccount("redisTest");
        redisService.setCacheObject("u",sysUser);
        SysUser user = redisService.getCacheObject("u", SysUser.class);
        return user.toString();

    }


    //测试参数合法校验的操作
    @GetMapping("/validation")
    public String validation(@Validated ValidationDTO dto){
        return "参数校验";
    }


}
